package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzThesaurusAttr;
import com.zzedu.dto.ZzThesaurusAttrDTO;
import com.zzedu.service.IZzThesaurusAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 单词属性Controller
 * 
 * @author Mr.Wang
 * @date 2025-01-29
 */
@RestController
@RequestMapping("/thesaurus/attr")
public class ZzThesaurusAttrController extends BaseController
{
    @Autowired
    private IZzThesaurusAttrService zzThesaurusAttrService;

    /**
     * 查询单词属性列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('thesaurus:attr:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzThesaurusAttrDTO zzThesaurusAttr)
    {
        return getDataTable(zzThesaurusAttrService.page(zzThesaurusAttr.getPageDTO(),zzThesaurusAttrService.buildQuery(zzThesaurusAttr)));
    }

    /**
     * 导出单词属性列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('thesaurus:attr:export')")
    @Log(title = "单词属性", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzThesaurusAttrDTO zzThesaurusAttr)
    {
        List<ZzThesaurusAttr> list = zzThesaurusAttrService.list(zzThesaurusAttrService.buildQuery(zzThesaurusAttr));
        ExcelUtil<ZzThesaurusAttr> util = new ExcelUtil<ZzThesaurusAttr>(ZzThesaurusAttr.class);
        util.exportExcel(ServletUtils.getResponse(),list, "单词属性数据");
    }




    /**
     * 新增保存单词属性
     */
    @PreAuthorize("@permission.hasAnyPermissions('thesaurus:attr:add')")
    @Log(title = "单词属性", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzThesaurusAttr zzThesaurusAttr)
    {
        return toAjax(zzThesaurusAttrService.save(zzThesaurusAttr));
    }



    /**
     * 获取单词属性详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('thesaurus:attr:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zzThesaurusAttrService.getById(id));
    }


    /**
     * 修改保存单词属性
     */
    @PreAuthorize("@permission.hasAnyPermissions('thesaurus:attr:edit')")
    @Log(title = "单词属性", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzThesaurusAttr zzThesaurusAttr)
    {
        return toAjax(zzThesaurusAttrService.updateById(zzThesaurusAttr));
    }

    /**
     * 删除单词属性
     */
    @PreAuthorize("@permission.hasAnyPermissions('thesaurus:attr:remove')")
    @Log(title = "单词属性", businessType = BusinessType.DELETE)
	@RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(zzThesaurusAttrService.removeBatchByIds(ids));
    }
}
